﻿using MediatR;
using Traceability.App.Apilication.Common.Slaughter;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure.Interfance;

namespace Traceability.App.Apilication.Handler.Slaughter
{
    public class GetSlaughterEnterHandler : IRequestHandler<GetSlaughterEnterComon, ApiResult<List<SlaughteringEnterprises>>>
    {
        private readonly IBaseRespository<SlaughteringEnterprises> slaughteringEnterprises;

        public GetSlaughterEnterHandler(IBaseRespository<SlaughteringEnterprises> SlaughteringEnterprises)
        {
            slaughteringEnterprises = SlaughteringEnterprises;
        }

        public Task<ApiResult<List<SlaughteringEnterprises>>> Handle(GetSlaughterEnterComon request, CancellationToken cancellationToken)
        {
            ApiResult<List<SlaughteringEnterprises>> res=new ApiResult<List<SlaughteringEnterprises>>();

            var info = slaughteringEnterprises.GetAll().Where(x => x.Production_Batch == request.Production_Batch).ToList();

            res.Message = "根据生产批次查询屠宰企业";
            res.Code = ApiEnum.Success;
            res.Data = info;
            return Task.FromResult(res);

        }
    }
}
